import allure

from test_pom.test4_八爪云接口自动化测试.base_api.base_api import BaseApi


class CommodityApi(BaseApi):
    base_url = "http://api.wxorder.taover.com"

    @allure.step("创建商品")
    def create_commodity(self, data):
        create_url = f"{self.base_url}/v1/goodsbase/"
        req = {
            "method": "post",
            "url": create_url,
            "json": data,
            "headers": {"Authorization": self.get_token()}
        }
        res = self.send_api(req)
        return res

    @allure.step("查询新建商品")
    def search_commodity(self, data):
        search_url = f"{self.base_url}/v1/goodsbase"
        req = {
            "method": "get",
            "url": search_url,
            "params": data,
            "headers": {"Authorization": self.get_token()}
        }
        res = self.send_api(req)
        return res

    @allure.step("下架商品")
    def take_off_commodity(self, goodsid):
        take_off_url = f"{self.base_url}/v1/wxordergoodsbasesku/updownstatus/0/sku/{goodsid}"
        req = {
            "method": "put",
            "url": take_off_url,
            "headers": {
                "Authorization": self.get_token(),
                "deviceId": "2LJ3EX4XWXSW5344VEM4I6YENKUNRTSGYZOL255OZPJKYDASA3ZOC7TE3EBNYP7BHACCYZCK36WHZ67A5W2GDWAKVI",
                "Accept": "application/json, text/plain, */*",
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 SLBrowser/9.0.6.5061 SLBChan/133 SLBVPV/64-bit",
                "Content-Type": "application/json;charset=UTF-8",
                "Origin": "http://wxorder.taover.com",
                "Referer": "http://wxorder.taover.com/",
                "Accept-Encoding": "gzip, deflate",
                "Accept-Language": "zh-CN,zh;q=0.9",
                "Connection": "keep-alive"
            },
            "json": {
                "sendMessageStatus": "0",
                "message": ""
            }
        }
        res = self.send_api(req)
        return res

    @allure.step("上架商品")
    def put_on_commodity(self, goodsid):
        put_on_url = f"{self.base_url}/v1/wxordergoodsbasesku/updownstatus/1/sku/{goodsid}"
        req = {
            "method": "put",
            "url": put_on_url,
            "headers": {
                "Authorization": self.get_token(),
                "deviceId": "2LJ3EX4XWXSW5344VEM4I6YENKUNRTSGYZOL255OZPJKYDASA3ZOC7TE3EBNYP7BHACCYZCK36WHZ67A5W2GDWAKVI",
                "Accept": "application/json, text/plain, */*",
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 SLBrowser/9.0.6.5061 SLBChan/133 SLBVPV/64-bit",
                "Content-Type": "application/json;charset=UTF-8",
                "Origin": "http://wxorder.taover.com",
                "Referer": "http://wxorder.taover.com/",
                "Accept-Encoding": "gzip, deflate",
                "Accept-Language": "zh-CN,zh;q=0.9",
                "Connection": "keep-alive"
            },
            "json": {
                "sendMessageStatus": "0",
                "message": ""
            }
        }
        res = self.send_api(req)
        return res


if __name__ == '__main__':
    print(CommodityApi().take_off_commodity(34512))
